//
//  CinPicTableViewCell.m
//  UI_APP_Project_Bean
//
//  Created by dllo on 16/6/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CinPicTableViewCell.h"
#import "DetiledMovieModel.h"
#import "GetHeightTools.h"
#import "MovieModel.h"

@interface CinPicTableViewCell ()
@property(nonatomic, retain)UIImageView *picImageView;
@property(nonatomic, retain)UILabel *scoreLabel;
@property(nonatomic, retain)UILabel *timeLabel;
@property(nonatomic, retain)UILabel *longLabel;
@property(nonatomic, retain)UILabel *typeLabel;
@property(nonatomic, retain)UILabel *countryLabel;
@property(nonatomic, retain)UILabel *produce;
@property(nonatomic, retain)UILabel *producerText;

@end



@implementation CinPicTableViewCell

- (void)dealloc
{
    [_picImageView release];
    [_scoreLabel release];
    [_timeLabel release];
    [_longLabel release];
    [_typeLabel release];
    [_countryLabel release];
    [_produce release];
    [_producerText release];
    [super dealloc];
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.picImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_picImageView];
        [_picImageView release];
        
        self.scoreLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_scoreLabel];
        [_scoreLabel release];
        
        
        self.timeLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_timeLabel];
        [_timeLabel release];
        
        
        self.longLabel = [[UILabel alloc]init];

        [self.contentView addSubview:_longLabel];
        [_longLabel release];
        
        
        
        self.typeLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_typeLabel];
        [_typeLabel release];
        
        
        self.countryLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_countryLabel];
        [_countryLabel release];
       
        
        self.produce = [[UILabel alloc]init];
        self.produce.font = [UIFont fontWithName:@"Damascus" size:21];
        [self.contentView addSubview:_produce];
        [_produce release];
        
        
        self.producerText = [[UILabel alloc]init];
        self.producerText.numberOfLines = 0;
        [self.contentView addSubview:_producerText];
        [_producerText release];
        
    }
    
    
    return self;
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    
    self.picImageView.frame = CGRectMake(15, 15, 150, 220);

    
    self.scoreLabel.frame = CGRectMake(_picImageView.frame.size.width + 30, _picImageView.frame.origin.y, 180, 30);
   

    self.timeLabel.frame = CGRectMake(_scoreLabel.frame.origin.x, _scoreLabel.frame.origin.y+45, _scoreLabel.frame.size.width, _scoreLabel.frame.size.height);
    
    
    
    self.longLabel.frame = CGRectMake(_timeLabel.frame.origin.x, _timeLabel.frame.origin.y + 45, _timeLabel.frame.size.width, _timeLabel.frame.size.height);
    
    
    
    self.typeLabel.frame = CGRectMake(_longLabel.frame.origin.x, _longLabel.frame.origin.y + 45, _longLabel.frame.size.width, _longLabel.frame.size.height);
  
    
    
    self.countryLabel.frame = CGRectMake(_typeLabel.frame.origin.x, _typeLabel.frame.origin.y + 45, _typeLabel.frame.size.width, _typeLabel.frame.size.height);
    
     self.produce.frame = CGRectMake(_picImageView.frame.origin.x, _picImageView.frame.size.height + 40, 200, 30);
    _produce.text = @"制作人";
    
    
    
    CGFloat height = [GetHeightTools heightWith:self.detiModel.actors];
    self.producerText.frame = CGRectMake(_produce.frame.origin.x, _picImageView.frame.size.height + 80,CGRectGetWidth(self.bounds)-20, height + 20);
    
    
}


-(void)setDetiModel:(DetiledMovieModel *)detiModel{
    
    if (_detiModel != detiModel) {
        [_detiModel release];
        _detiModel = [detiModel retain];
    }
    self.scoreLabel.text = [NSString stringWithFormat:@"评分: %@  (%@评论)", detiModel.rating,  detiModel.rating_count];
    self.timeLabel.text = detiModel.release_date;
    self.longLabel.text = detiModel.runtime;
    self.typeLabel.text = detiModel.genres;
    self.countryLabel.text = detiModel.film_locations;
    self.producerText.text = detiModel.actors;
//    self.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:detiModel.poster]]];
    
}

-(void)setModel:(MovieModel *)model{
    
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    self.picImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.model.pic_url]]];
    
}







@end
